﻿using System.Net.Http;
using System.Text;
using System.Text.Json;
using MeterReader.WPF.Models;

namespace MeterReader.WPF.Services
{
    public class SaveDataService : ISaveData
    {
        private readonly HttpClient _httpClient = new HttpClient();

        public async Task PostDataAsync(string url, TMeter meter)
        {
            var options = new JsonSerializerOptions { PropertyNamingPolicy = null };
            var json = JsonSerializer.Serialize(meter, options);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            var response = await _httpClient.PostAsync(url, content);

            if (response.IsSuccessStatusCode)
            {
                var responseString = await response.Content.ReadAsStringAsync();
                // 处理响应
            }
        }
    }
}
